{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 85\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_By using list comprehension, please write a program to print the list after removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use list comprehension to delete a bunch of element from a list.Use enumerate() to get (index, value) tuple._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li = [12, 24, 35, 70, 88, 120, 155]\n",
    "li = [li[i] for i in range(len(li)) if i not in (0, 4, 5)]\n",
    "print(li)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 86\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_By using list comprehension, please write a program to print the list after removing the value 24 in [12,24,35,24,88,120,155]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use list's remove method to delete a value._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li = [12, 24, 35, 24, 88, 120, 155]\n",
    "li.remove(24)  # this will remove only the first occurrence of 24\n",
    "print(li)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 87\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_With two given lists [1,3,6,78,35,55] and [12,24,35,24,88,120,155], write a program to make a list whose elements are intersection of the above given lists._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use set() and \"&=\" to do set intersection operation._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = [1, 3, 6, 78, 35, 55]\n",
    "list2 = [12, 24, 35, 24, 88, 120, 155]\n",
    "set1 = set(list1)\n",
    "set2 = set(list2)\n",
    "intersection = set1 & set2\n",
    "print(intersection)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = [1, 3, 6, 78, 35, 55]\n",
    "list2 = [12, 24, 35, 24, 88, 120, 155]\n",
    "set1 = set(list1)\n",
    "set2 = set(list2)\n",
    "intersection = set.intersection(set1, set2)\n",
    "print(intersection)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 88\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_With a given list [12,24,35,24,88,120,155,88,120,155], write a program to print this list after removing all duplicate values with original order reserved._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use set() to store a number of values without duplicate._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li = [12, 24, 35, 24, 88, 120, 155, 88, 120, 155]\n",
    "for i in li:\n",
    "    if li.count(i) > 1:\n",
    "        li.remove(i)\n",
    "print(li)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def removeDuplicate(li):\n",
    "    seen = {}  # dictionary\n",
    "    for item in li:\n",
    "        if item not in seen:\n",
    "            seen[item] = True\n",
    "            yield item\n",
    "\n",
    "\n",
    "li = [12, 24, 35, 24, 88, 120, 155, 88, 120, 155]\n",
    "ans = list(removeDuplicate(li))\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 89\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Define a class Person and its two child classes: Male and Female. All classes have a method \"getGender\" which can print \"Male\" for Male class and \"Female\" for Female class._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use Subclass(Parentclass) to define a child class._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solution:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Person(object):\n",
    "    def getGender(self):\n",
    "        return \"Unknown\"\n",
    "\n",
    "\n",
    "class Male(Person):\n",
    "    def getGender(self):\n",
    "        return \"Male\"\n",
    "\n",
    "\n",
    "class Female(Person):\n",
    "    def getGender(self):\n",
    "        return \"Female\"\n",
    "\n",
    "\n",
    "aMale = Male()\n",
    "aFemale = Female()\n",
    "print(aMale.getGender())\n",
    "print(aFemale.getGender())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
